package learning.groovy.gstring

class GStringDemo {
	static main(args){
		//1、简单的$语法
		def me = 'Tarzan'
		def you = 'Jane'
		def line = "me $me - you $you"
		println line
		
		//2、扩展的简单语法
		def date = new Date(0)
		def out = "Year $date.year Month $date.month Day $date.date"
		println out
		
		//3、使用花括号表示的完整语法
		//在花括号中可以是任意的groovy表达式，花括号表示一个闭包
		out = "Date is ${date.toGMTString()}!"
		println out
		
		//4、多行的GString
		def sql = """
		SELECT * FROM MyTable
		  WHERE Year = $date.year
		"""
		println sql
		
		//5、$作为字符串的一部分
		out = "my 0.02\$"
		println out
		
		//==============
		def greeting = 'Hello'
		greeting <<= ' Groovy' //追加文本和赋值一起完成
		println greeting 
		println greeting instanceof java.lang.StringBuffer
		println greeting instanceof java.lang.String
		
		greeting << '!' //在StringBuffer上追加文本
		println greeting
		
		greeting[1..4] = 'i' //将子串"ello"替换为"i"
		println greeting
		
	}
}
